package cn.itcast.reggie.service.impl;

import cn.itcast.reggie.dto.SetmealDto;
import cn.itcast.reggie.mapper.SetmealDishMapper;
import cn.itcast.reggie.mapper.SetmealMapper;
import cn.itcast.reggie.pojo.Setmeal;
import cn.itcast.reggie.pojo.SetmealDish;
import cn.itcast.reggie.service.SetmealService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {

    @Autowired
    private SetmealDishMapper setmealDishMapper;

    @Override
    public void saveDto(SetmealDto setmealDto) {
        save(setmealDto);//保存套餐
        //保存套餐和菜品关系
        List<SetmealDish> dishList = setmealDto.getSetmealDishes();
        for (SetmealDish setmealDish : dishList) {
            setmealDish.setSetmealId(setmealDto.getId());
            setmealDishMapper.insert(setmealDish);
        }
    }
}